<template>
  <div id="topSearch">
    <div class="search-box">
      <el-form :inline="true" :model="searchInfo" ref="ruleForm">
        <el-form-item label="筛选用户" prop="userType">
          <el-select
            size="small"
            v-model="searchInfo.userType"
            placeholder="请选择"
            clearable
          >
            <el-option
              v-for="(item, index) in userTypeList"
              :key="index"
              :label="item.dictLabel"
              :value="item.dictValue"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="筛选时间" prop="createTime">
          <el-date-picker
            size="small"
            v-model="searchInfo.createTime"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="检索用户" prop="searchType">
          <el-select
            size="small"
            v-model="searchInfo.searchType"
            placeholder="请选择"
            clearable
          >
            <el-option
              v-for="(item, index) in searchTypeList"
              :key="index"
              :label="item.dictLabel"
              :value="item.dictValue"
            >
            </el-option>
          </el-select>
          <el-input
            size="small"
            v-model="searchInfo.searchValue"
            placeholder="请输入想查询的用户"
            clearable
            maxlength="50"
            style="width: 204px"
          ></el-input>
        </el-form-item>
        <el-form-item label="学院" prop="collegeId">
          <el-select
            size="small"
            v-model="searchInfo.collegeId"
            placeholder="请选择"
            clearable
          >
            <el-option
              v-for="(item, index) in collegeList"
              :key="index"
              :label="item.dictLabel"
              :value="item.dictValue"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="s-btn">
          <el-button type="success" icon="el-icon-search" @click="toSearch">
            筛选
          </el-button>
          <el-button type="success" plain @click="resetForm('ruleForm')">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
import { sysNormalDisable } from '@utils/dictionariesFunc'
export default {
  data() {
    return {
      searchInfo: {
        userType: '', //筛选用户
        startTime: '', //开始时间
        stopTime: '', //结束时间
        searchType: '', //检索类型
        searchValue: '', //检索用户
        collegeId: '', //学院
        createTime: []
      },
      userTypeList: [
        { dictLabel: 'A用户', dictValue: 'A' },
        { dictLabel: 'B用户', dictValue: 'B' }
      ],
      searchTypeList: [
        { dictLabel: '用户OpenID', dictValue: 'OPENID' },
        { dictLabel: '用户手机号', dictValue: 'PHONE' }
      ],
      collegeList: []
    }
  },
  async mounted() {
    /* 字典  学院 */
    this.collegeList = await sysNormalDisable('sys_college')
  },
  watch: {
    'searchInfo.createTime': {
      handler(newVal) {
        this.searchInfo.startTime = newVal && newVal.length > 1 ? newVal[0] : ''
        this.searchInfo.stopTime = newVal && newVal.length > 1 ? newVal[1] : ''
      },
      deep: true
    }
  },
  methods: {
    toSearch() {
      const obj = Object.assign({}, this.searchInfo)
      delete obj.createTime
      this.$emit('toSearch', obj)
    },
    resetForm(formName) {
      this.$refs[formName].resetFields()
      this.searchInfo.searchValue = ''
    }
  }
}
</script>
<style lang="less" scoped></style>
